#!/bin/Rscript

op_100_20_1 <- read.table("risco_1_5_10/erro_20/rf/profits.dat")$V1
op_100_m20_1 <- read.table("risco_1_5_10/erro_m20/rf/profits.dat")$V1
op_100_0_1 <- read.table("risco_1_5_10/erro_0/rf/profits.dat")$V1

op_100_20_5 <- read.table("risco_5_10_50/erro_20/rf/profits.dat")$V1
op_100_m20_5 <- read.table("risco_5_10_50/erro_m20/rf/profits.dat")$V1
op_100_0_5 <- read.table("risco_5_10_50/erro_0/rf/profits.dat")$V1

on_100_0_1 <- read.table("risco_1_5_10/erro_0/on/profits.dat")$V1
on_100_0_5 <- read.table("risco_5_10_50/erro_0/on/profits.dat")$V1

ut_100_20_1 <- read.table("risco_1_5_10/erro_20/ut/profits.dat")$V1
ut_100_m20_1 <- read.table("risco_1_5_10/erro_m20/ut/profits.dat")$V1
ut_100_0_1 <- read.table("risco_1_5_10/erro_0/ut/profits.dat")$V1

ut_100_20_5 <- read.table("risco_5_10_50/erro_20/ut/profits.dat")$V1
ut_100_m20_5 <- read.table("risco_5_10_50/erro_m20/ut/profits.dat")$V1
ut_100_0_5 <- read.table("risco_5_10_50/erro_0/ut/profits.dat")$V1

iosup_100_20_1 <- read.table("risco_1_5_10/erro_20/iosup/profits.dat")$V1
iosup_100_m20_1 <- read.table("risco_1_5_10/erro_m20/iosup/profits.dat")$V1
iosup_100_0_1 <- read.table("risco_1_5_10/erro_0/iosup/profits.dat")$V1

iosup_100_20_5 <- read.table("risco_5_10_50/erro_20/iosup/profits.dat")$V1
iosup_100_m20_5 <- read.table("risco_5_10_50/erro_m20/iosup/profits.dat")$V1
iosup_100_0_5 <- read.table("risco_5_10_50/erro_0/iosup/profits.dat")$V1

super_100_20_1 <- read.table("risco_1_5_10/erro_20/super/profits.dat")$V1
super_100_m20_1 <- read.table("risco_1_5_10/erro_m20/super/profits.dat")$V1
super_100_0_1 <- read.table("risco_1_5_10/erro_0/super/profits.dat")$V1

super_100_20_5 <- read.table("risco_5_10_50/erro_20/super/profits.dat")$V1
super_100_m20_5 <- read.table("risco_5_10_50/erro_m20/super/profits.dat")$V1
super_100_0_5 <- read.table("risco_5_10_50/erro_0/super/profits.dat")$V1

# Verificando influencia do fator risco nos lucros
print("Analise do fator risco")

print("\nAnalise OP\n")

print("100 us, Erro 20% OP 1% == OP 5%")
t.test(op_100_20_1, op_100_20_5, paired=TRUE, var.equal=FALSE)
print("100 us, Erro 20% OP 1% > OP 5%")
t.test(op_100_20_1, op_100_20_5, paired=TRUE, var.equal=FALSE, alternative="less")

print("100 us, Erro m20% OP 1% == OP 5%")
t.test(op_100_m20_1, op_100_m20_5, paired=TRUE, var.equal=FALSE)
print("100 us, Erro m20% OP 1% > OP 5%")
t.test(op_100_m20_1, op_100_m20_5, paired=TRUE, var.equal=FALSE, alternative="less")

print("100 us, Erro 0% OP 1% == OP 5%")
t.test(op_100_0_1, op_100_0_5, paired=TRUE, var.equal=FALSE)
print("100 us, Erro 0% OP 1% > OP 5%")
t.test(op_100_0_1, op_100_0_5, paired=TRUE, var.equal=FALSE, alternative="less")

print("\nAnalise UT\n")

print("100 us, Erro 20% UT 1% == UT 5%")
t.test(ut_100_20_1, ut_100_20_5, paired=TRUE, var.equal=FALSE)
print("100 us, Erro 20% ut 1% > ut 5%")
t.test(ut_100_20_1, ut_100_20_5, paired=TRUE, var.equal=FALSE, alternative="less")

print("100 us, Erro m20% ut 1% == ut 5%")
t.test(ut_100_m20_1, ut_100_m20_5, paired=TRUE, var.equal=FALSE)
print("100 us, Erro m20% ut 1% > ut 5%")
t.test(ut_100_m20_1, ut_100_m20_5, paired=TRUE, var.equal=FALSE, alternative="less")

print("100 us, Erro 0% ut 1% == ut 5%")
t.test(ut_100_0_1, ut_100_0_5, paired=TRUE, var.equal=FALSE)
print("100 us, Erro 0% ut 1% > ut 5%")
t.test(ut_100_0_1, ut_100_0_5, paired=TRUE, var.equal=FALSE, alternative="less")

print("\nAnalise Iosup\n")

print("100 us, Erro 20% iosup 1% == iosup 5%")
t.test(iosup_100_20_1, iosup_100_20_5, paired=TRUE, var.equal=FALSE)
print("100 us, Erro 20% iosup 1% > iosup 5%")
t.test(iosup_100_20_1, iosup_100_20_5, paired=TRUE, var.equal=FALSE, alternative="less")

print("100 us, Erro m20% iosup 1% == iosup 5%")
t.test(iosup_100_m20_1, iosup_100_m20_5, paired=TRUE, var.equal=FALSE)
print("100 us, Erro m20% iosup 1% > iosup 5%")
t.test(iosup_100_m20_1, iosup_100_m20_5, paired=TRUE, var.equal=FALSE, alternative="less")

print("100 us, Erro 0% iosup 1% == iosup 5%")
t.test(iosup_100_0_1, iosup_100_0_5, paired=TRUE, var.equal=FALSE)
print("100 us, Erro 0% iosup 1% > iosup 5%")
t.test(iosup_100_0_1, iosup_100_0_5, paired=TRUE, var.equal=FALSE, alternative="less")

print("\nAnalise Super\n")

print("100 us, Erro 20% super 1% == super 5%")
t.test(super_100_20_1, super_100_20_5, paired=TRUE, var.equal=FALSE)
print("100 us, Erro 20% super 1% > super 5%")
t.test(super_100_20_1, super_100_20_5, paired=TRUE, var.equal=FALSE, alternative="less")

print("100 us, Erro m20% super 1% == super 5%")
t.test(super_100_m20_1, super_100_m20_5, paired=TRUE, var.equal=FALSE)
print("100 us, Erro m20% super 1% > super 5%")
t.test(super_100_m20_1, super_100_m20_5, paired=TRUE, var.equal=FALSE, alternative="less")

print("100 us, Erro 0% super 1% == super 5%")
t.test(super_100_0_1, super_100_0_5, paired=TRUE, var.equal=FALSE)
print("100 us, Erro 0% super 1% > super 5%")
t.test(super_100_0_1, super_100_0_5, paired=TRUE, var.equal=FALSE, alternative="less")

print("\nAnalise on\n")

print("100 us, Erro 0% on 1% == on 5%")
t.test(on_100_0_1, on_100_0_5, paired=TRUE, var.equal=FALSE)
print("100 us, Erro 0% on 1% > on 5%")
t.test(on_100_0_1, on_100_0_5, paired=TRUE, var.equal=FALSE, alternative="less")



# Verificando influencia do fator risco nos ganhos
print("Analise do fator risco nos ganhos")

gop_100_20_1 <- (op_100_20_1 - on_100_20_1) / abs(on_100_20_1)
gop_100_m20_1 <- (op_100_m20_1 - on_100_m20_1) / abs(on_100_m20_1)
gop_100_0_1 <- (op_100_0_1 - on_100_0_1) / abs(on_100_0_1)

gop_100_20_5 <- (op_100_20_5 - on_100_20_5) / abs(on_100_20_5)
gop_100_m20_5 <- (op_100_m20_5 - on_100_m20_5) / abs(on_100_m20_5)
gop_100_0_5 <- (op_100_0_5 - on_100_0_5) / abs(on_100_0_5)

gut_100_20_1 <- (ut_100_20_1 - on_100_20_1) / abs(on_100_20_1)
gut_100_m20_1 <- (ut_100_m20_1 - on_100_m20_1) / abs(on_100_m20_1)
gut_100_0_1 <- (ut_100_0_1 - on_100_0_1) / abs(on_100_0_1)

gut_100_20_5 <- (ut_100_20_5 - on_100_20_5) / abs(on_100_20_5)
gut_100_m20_5 <- (ut_100_m20_5 - on_100_m20_5) / abs(on_100_m20_5)
gut_100_0_5 <- (ut_100_0_5 - on_100_0_5) / abs(on_100_0_5)

giosup_100_20_1 <- (iosup_100_20_1 - on_100_0_1) / abs(on_100_0_1)
giosup_100_m20_1 <- (iosup_100_m20_1 - on_100_0_1) / abs(on_100_0_1)
giosup_100_0_1 <- (iosup_100_0_1 - on_100_0_1) / abs(on_100_0_1)

giosup_100_20_5 <- (iosup_100_20_5 - on_100_0_5) / abs(on_100_0_5)
giosup_100_m20_5 <- (iosup_100_m20_5 - on_100_0_5) / abs(on_100_0_5)
giosup_100_0_5 <- (iosup_100_0_5 - on_100_0_5) / abs(on_100_0_5)

gsuper_100_20_1 <- (super_100_20_1 - on_100_0_1) / abs(on_100_0_1)
gsuper_100_m20_1 <- (super_100_m20_1 - on_100_0_1) / abs(on_100_0_1)
gsuper_100_0_1 <- (super_100_0_1 - on_100_0_1) / abs(on_100_0_1)

gsuper_100_20_5 <- (super_100_20_5 - on_100_0_5) / abs(on_100_0_5)
gsuper_100_m20_5 <- (super_100_m20_5 - on_100_0_5) / abs(on_100_0_5)
gsuper_100_0_5 <- (super_100_0_5 - on_100_0_5) / abs(on_100_0_5)

print("\nAnalise ganho OP\n")

print("100 us, 20% OP 1% == OP 5%")
t.test(gop_100_20_1, gop_100_20_5, paired=TRUE, var.equal=FALSE)
print("100 us, 20% OP 1% > OP 5%")
t.test(gop_100_20_1, gop_100_20_5, paired=TRUE, var.equal=FALSE, alternative="less")

print("100 us, m20% OP 1% == OP 5%")
t.test(gop_100_m20_1, gop_100_m20_5, paired=TRUE, var.equal=FALSE)
print("100 us, m20% OP 1% > OP 5%")
t.test(gop_100_m20_1, gop_100_m20_5, paired=TRUE, var.equal=FALSE, alternative="less")

print("100 us, 0% OP 1% == OP 5%")
t.test(gop_100_0_1, gop_100_0_5, paired=TRUE, var.equal=FALSE)
print("100 us, 0% OP 1% > OP 5%")
t.test(gop_100_0_1, gop_100_0_5, paired=TRUE, var.equal=FALSE, alternative="less")


print("\nAnalise UT\n")

print("100 us, 20% ut 1% == ut 5%")
t.test(gut_100_20_1, gut_100_20_5, paired=TRUE, var.equal=FALSE)
print("100 us, 20% ut 1% > ut 5%")
t.test(gut_100_20_1, gut_100_20_5, paired=TRUE, var.equal=FALSE, alternative="less")

print("100 us, m20% ut 1% == ut 5%")
t.test(gut_100_m20_1, gut_100_m20_5, paired=TRUE, var.equal=FALSE)
print("100 us, m20% ut 1% > ut 5%")
t.test(gut_100_m20_1, gut_100_m20_5, paired=TRUE, var.equal=FALSE, alternative="less")

print("100 us, 0% ut 1% == ut 5%")
t.test(gut_100_0_1, gut_100_0_5, paired=TRUE, var.equal=FALSE)
print("100 us, 0% ut 1% > ut 5%")
t.test(gut_100_0_1, gut_100_0_5, paired=TRUE, var.equal=FALSE, alternative="less")

print("\nAnalise ganho Iosup\n")

print("100 us, 20% giosup 1% == giosup 5%")
t.test(giosup_100_20_1, giosup_100_20_5, paired=TRUE, var.equal=FALSE)
print("100 us, 20% giosup 1% > giosup 5%")
t.test(giosup_100_20_1, giosup_100_20_5, paired=TRUE, var.equal=FALSE, alternative="less")

print("100 us, m20% giosup 1% == giosup 5%")
t.test(giosup_100_m20_1, giosup_100_m20_5, paired=TRUE, var.equal=FALSE)
print("100 us, m20% giosup 1% > giosup 5%")
t.test(giosup_100_m20_1, giosup_100_m20_5, paired=TRUE, var.equal=FALSE, alternative="less")

print("100 us, 0% giosup 1% == giosup 5%")
t.test(giosup_100_0_1, giosup_100_0_5, paired=TRUE, var.equal=FALSE)
print("100 us, 0% giosup 1% > giosup 5%")
t.test(giosup_100_0_1, giosup_100_0_5, paired=TRUE, var.equal=FALSE, alternative="less")

print("\nAnalise ganho super\n")

print("100 us, 20% gsuper 1% == gsuper 5%")
t.test(gsuper_100_20_1, giosup_100_20_5, paired=TRUE, var.equal=FALSE)
print("100 us, 20% gsuper 1% > gsuper 5%")
t.test(gsuper_100_20_1, gsuper_100_20_5, paired=TRUE, var.equal=FALSE, alternative="less")

print("100 us, m20% gsuper 1% == gsuper 5%")
t.test(gsuper_100_m20_1, gsuper_100_m20_5, paired=TRUE, var.equal=FALSE)
print("100 us, m20% gsuper 1% > gsuper 5%")
t.test(gsuper_100_m20_1, gsuper_100_m20_5, paired=TRUE, var.equal=FALSE, alternative="less")

print("100 us, 0% gsuper 1% == gsuper 5%")
t.test(gsuper_100_0_1, gsuper_100_0_5, paired=TRUE, var.equal=FALSE)
print("100 us, 0% gsuper 1% > gsuper 5%")
t.test(gsuper_100_0_1, gsuper_100_0_5, paired=TRUE, var.equal=FALSE, alternative="less")
